<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function* gen() {
        let result = yield request();
        result = JSON.parse(result);
        console.log(result);
    }

    // 模拟异步发送请求，2s后拿数据，把数据做为next的参数，用于下一步操作
    function request() {
        setTimeout(function () {
            it.next('{"a":1,"b":2}');
        }, 2000);
    }
    const it = gen();
    it.next(); // {a: 1, b: 2}





</script>
</body>
</html>